# -*- coding: utf-8 -*-
# @Time    : 2018/8/1 11:16
import os
path = os.path.abspath(os.path.dirname(os.getcwd()))
import sys
sys.path.append(path)
import pymongo
import config
from collections import OrderedDict
from datetime import datetime

db = pymongo.MongoClient(config.MONGODB_URI)[config.MONGODB_NAME]
# 元数据
# li_db = db[config.COLLECTION_NAME_baidu]
# 关键词
li_db_words = db[config.WORDS_NAME]

class zd(object):
    # 插入元数据字段
    def zdf(self):
        save = OrderedDict()
        save["update_time"] = datetime.now()
        save['state'] =0
        save['download'] = 0

        return save

    # 插入关键字字段
    def zdf_two(self):
        save = OrderedDict()
        save['state_google'] = 0
        save['state_baidu'] = 0
        save['state_biying'] = 0
        save['state_sougou'] = 0
        return save

class insert_mongo(object):
    def __init__(self) -> None:
        self.zd = zd()
    def insert_mongo_word(self,key):
        try:
            save = self.zd.zdf_two()
            save["word"] = key
            li_db_words.insert(save)
            print("关键词插入mongo")
        except Exception as e:
            print(e)